package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtMaintenanceRecord;
import com.yuetong.business.service.IYtMaintenanceRecordService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 维修记录，用于存储电梯的维护记录Controller
 *
 * @author  卓晓君
 * @date 2025-02-04
 */
@RestController
@RequestMapping("/business/record")
public class YtMaintenanceRecordController extends BaseController
{
    @Autowired
    private IYtMaintenanceRecordService ytMaintenanceRecordService;

    /**
     * 查询维修记录，用于存储电梯的维护记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtMaintenanceRecord ytMaintenanceRecord)
    {
        startPage();
        List<YtMaintenanceRecord> list = ytMaintenanceRecordService.selectYtMaintenanceRecordList(ytMaintenanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出维修记录，用于存储电梯的维护记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:record:export')")
    @Log(title = "维修记录，用于存储电梯的维护记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtMaintenanceRecord ytMaintenanceRecord)
    {
        List<YtMaintenanceRecord> list = ytMaintenanceRecordService.selectYtMaintenanceRecordList(ytMaintenanceRecord);
        ExcelUtil<YtMaintenanceRecord> util = new ExcelUtil<YtMaintenanceRecord>(YtMaintenanceRecord.class);
        util.exportExcel(response, list, "维修记录，用于存储电梯的维护记录数据");
    }

    /**
     * 获取维修记录，用于存储电梯的维护记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(ytMaintenanceRecordService.selectYtMaintenanceRecordByRecordId(recordId));
    }

    /**
     * 新增维修记录，用于存储电梯的维护记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:add')")
    @Log(title = "维修记录，用于存储电梯的维护记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtMaintenanceRecord ytMaintenanceRecord)
    {
        return toAjax(ytMaintenanceRecordService.insertYtMaintenanceRecord(ytMaintenanceRecord));
    }

    /**
     * 修改维修记录，用于存储电梯的维护记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:edit')")
    @Log(title = "维修记录，用于存储电梯的维护记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtMaintenanceRecord ytMaintenanceRecord)
    {
        return toAjax(ytMaintenanceRecordService.updateYtMaintenanceRecord(ytMaintenanceRecord));
    }

    /**
     * 删除维修记录，用于存储电梯的维护记录
     */
    @PreAuthorize("@ss.hasPermi('business:record:remove')")
    @Log(title = "维修记录，用于存储电梯的维护记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(ytMaintenanceRecordService.deleteYtMaintenanceRecordByRecordIds(recordIds));
    }
}
